var tickId = sessionStorage.getItem("tickId");
var tickaId = sessionStorage.getItem("tickaId");

function backDeviceGroupAdd() {
	window.location.href = 'userParameter.jsp';

}

$.ajax({
	url: 'paramTypeList',
	type: 'POST',
	data: {
		session: $.Cookie("session"),
		userId: $.Cookie("userId"),
		companyId: $.Cookie("companyId"),
		index: 0,
		page: 20

	},
	dataType: 'json',
	success: function(data) {
		if(data.errorCode == 0) {
			arr = data.result.paramTypeList;
			for(var i = 0; i < arr.length; i++) {
				if(arr[i].id == tickaId) {
					if(arr[i].type == 'DVC_TYPE') {
						$("#paramKey").attr("value", arr[i].paramKey);
						$("#paramKey").attr("name", arr[i].id);
						$("#paramValue").attr("value", arr[i].paramValue);
						$("#desc").attr("value", arr[i].paramDesc);
						$("#type").attr("value", "设备类型");
					} else {
						$("#paramKey").attr("value", arr[i].paramKey);
						$("#paramKey").attr("name", arr[i].id);
						$("#paramValue").attr("value", arr[i].paramValue);
						$("#desc").attr("value", arr[i].paramDesc);
						$("#type").attr("value", "机构类型");
					}
				}

			}
		} else if(data.errorCode == -6) {
			alert("登录超时！")
			top.location.href = 'index.jsp';
		} else {
			alert("请重试！")
		}
	},
	error: function(err) {
		alert("连接服务器失败！请重新提交！");
		top.location.href = 'index.jsp';
	}
});

function submitData() {
	if(!$("#abc option:selected").val() == "" || !$("#paramKey").val() == "" || !$("#paramValue").val() == "") {
		var param = {
			session: $.Cookie("session"),
			userId: $.Cookie("userId"),
			companyId: $.Cookie("companyId"),
			paramId: $("#paramKey").attr("name"),
			paramValue: $("#paramValue").val(),
			desc: $("#desc").val(),
			flag: '0',
		};
		$.ajax({
			url: 'paramTypeOperation',
			type: 'POST',
			data: param,
			dataType: 'json',
			success: function(data) {
				console.log(data)
				if(data.errorCode == 0) {
					alert("提交成功了！")
					window.location.href = 'userParameter.jsp';
				} else if(data.errorCode == -6) {
					alert("登录超时！")
				} else if(data.errorCode == -301) {
					alert("基础数据已存在！请勿重新添加！")
				} else {
					alert("请重试！")
				};
			},
			error: function(err) {
				alert("连接服务器失败！请重新提交！");
				top.location.href = 'index.jsp';

			}
		});
	}

}

function cleanupDevice() {
	$("#paramValue").attr("value", "");
	$("#desc").attr("value", "");
}